const { Service } = require("egg")
class UserOrBookService extends Service {
  async addUserBook(data) {
    const result = await this.app.mysql.insert("egg_user_book", data)
    return result
  }
  async getUserBook(id) {
    const result = await this.app.mysql.query(
      `SELECT egg_book.* from egg_user_book
        INNER JOIN egg_book 
        on egg_book.id = egg_user_book.book_id 
        WHERE egg_user_book.user_id = ?`,
      [id]
    )
    return result
  }
  async isExist(data){
    const result = await this.app.mysql.query(
      `SELECT egg_user_book.user_id,egg_user_book.book_id 
      FROM egg_user_book WHERE user_id=? and book_id=?`,
      [data.user_id,data.book_id]
    )
    return result
  }

}
module.exports = UserOrBookService
